// const myHeading = document.querySelector("h1");
// myHeading.textContent = "Hello world123!";

// document.querySelector("html").addEventListener("click", function () {
//     alert("别戳我，我怕疼！");
//   });

const myImage = document.querySelector("img");
let myButton = document.querySelector("button");
let myHeading = document.querySelector("h1");

function setUserName() {
    const myName = prompt("Please enter your name.");
    if (!myName) {
      setUserName();
    } else {
      localStorage.setItem("name", myName);
      myHeading.textContent = `Mozilla is cool, ${myName}`;
    }
}

myImage.onclick = () => {
  const mySrc = myImage.getAttribute("src");
  if (mySrc === "images/hm.jpg") {
    myImage.setAttribute("src", "images/hm1.jpg");
  } else {
    myImage.setAttribute("src", "images/hm.jpg");
  }
};

myButton.onclick = function () {
    setUserName();
};
  

localStorage.clear();
if (!localStorage.getItem("name")) {
    setUserName();
} else {
    const storedName = localStorage.getItem("name");
    myHeading.textContent = `Mozilla is cool, ${storedName}`;
}
